import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from 'element-plus/es/locale/lang/zh-cn'

import App from './App.vue'
import router from './router'
import { setupDirectives } from './directives'
import { setupGlobalProperties } from './utils/global'
import { setupVueErrorHandler } from './utils/errorHandler'
import { setupGlobalUtils } from './utils/commonUtils'
import { startPerformanceMonitoring } from './utils/performance'

// 样式
import '@/styles/index.scss'

const app = createApp(App)

// 状态管理
app.use(createPinia())

// 路由
app.use(router)

// UI组件库
app.use(ElementPlus, {
  locale: zhCn,
  size: 'default'
})

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 全局指令
setupDirectives(app)

// 全局属性
setupGlobalProperties(app)

// 全局工具函数
setupGlobalUtils(app)

// 错误处理
setupVueErrorHandler(app)

// 性能监控
startPerformanceMonitoring()

// 挂载应用
app.mount('#app')
